/*
 * ====================================================================
 * Copyright (c) 2002-2018 The RapidSVN Group.  All rights reserved.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program (in the file GPL.txt).
 * If not, see <http://www.gnu.org/licenses/>.
 *
 * This software consists of voluntary contributions made by many
 * individuals.  For exact contribution history, see the revision
 * history and logs, available at http://rapidsvn.tigris.org/.
 * ====================================================================
 */
#ifndef _THREADED_WORKER_H_
#define _THREADED_WORKER_H_

// app
#include "action_worker.hpp"

// forward declarations
class wxWindow;
class SvnAction;


/*
 * 开启任务
 * 阻塞
 * wifi message monitor thread
 * 开启，默认启动
 * worker->thread
 * actions
 * event
 * business
 */
class ThreadedWorker: public AbstractActionWorker{
protected:
    wxVector<AbstractAction> actions;
public:
    explicit ThreadedWorker( MyTagApp* myTagApp, wxWindow * parent = nullptr );
    ~ThreadedWorker() override;

    void Create(wxWindow * parent) override;

    //report the job run session
    ActionState GetState() override;
    ActionResult GetResult() override;

    void SetTracer(Tracer * tr) override;

    //accept the job and run the job if possible
    bool Perform(AbstractAction * abstractAction) override;
    bool Perform(NormalAction * normalAction);
    bool Perform(SvnAction * svnAction);
    //bool Perform(GitAction * gitAction);
private:
    //the thread that for running
    class WorkThread;
    //
    WorkThread * workThread;
};

//
class SvnThreadedWorker : public ActionWorker
{
public:
  explicit SvnThreadedWorker(wxWindow * parent = nullptr);
  ~SvnThreadedWorker() override;

  //
  void Create(wxWindow * parent) override;

  //
  ActionState GetState() override;
  ActionResult GetResult() override;

  void SetTracer(Tracer * tr) override;
  void SetSvnContext(svn::Context * context, bool own = false) override;

  svn::Context * GetSvnContext() const override;

  SvnThreadedWorker(const SvnThreadedWorker &) =delete;
  bool Perform(SvnAction * action) override;
private:
  class WorkThread;
  WorkThread * workThread;
};

/*
 * action, thread两条线
 * //服务线程，通用服务线程
 * 任务容器
 * worker and thread
 * worker里有任务容器.vector<Action>
 * 需求:
 * just in the main_frame.cpp
 * both svn/git
 * background process mechanism
 */
class ContextThreadedWorker : public ActionWorker
{
public:
    //action event to the parent by the thread
    explicit ContextThreadedWorker( MyTagApp* myTagApp, wxWindow * parent = nullptr);
    ~ContextThreadedWorker() override;

    void Create( MyTagApp* myTagApp, wxWindow * parent) ;
    void Create( wxWindow * parent) override;

    ActionState GetState() override;
    ActionResult GetResult() override;
    //
    void SetTracer(Tracer * tr) override;
    //add dependency: svn context, git context, put into the thread
    //file browser, on click
    //work dir, work context
    void SetSvnContext( svn::Context * context, bool own = false) override;

    //mix the context to the thread, use the context to do the special job
    //action
    void SetGitContext( GitContext* context, bool own = false ) override;

    svn::Context * GetSvnContext() const override;
    GitContext* GetGitContext() const override;

    ContextThreadedWorker(const ContextThreadedWorker &) =delete;

    bool Perform(NormalAction * normalAction) override;
    bool Perform(SvnAction * action) override;
    bool Perform(GitAction * gitAction) override;
private:
    //put into the thread
    class WorkThread;
    WorkThread * workThread;
    //WorkThread::svnContext
    //action::svnContext
    //main frame view to set the current context
    //
};
#endif
/* -----------------------------------------------------------------
 * local variables:
 * eval: (load-file "../rapidsvn-dev.el")
 * end:
 */
